<?php
    session_start();
    require_once '../includes/runtime/lib/Propel.php';
    Propel::init("../includes/build/conf/easylib-conf.php");
    set_include_path("../includes/build/classes" . PATH_SEPARATOR . get_include_path());
    $email=$_POST['email'];
    $id=$_POST['id'];
    $station=  TabStationQuery::create()->filterByIdStation($id)->findOne();
    $infoStation = TabInformationStationQuery::create()->filterByFkStation($station->getIdStation())->orderByIdInformation(Criteria::DESC)->findOne();
    $user=  TabAbonneQuery::create()->filterByEmail($email)->findOne();
    if(count($user)<1)
        atomik::flash('user null');
    $utilisation=  TabUtilisationQuery::create()->filterByFkAbonne($user->getIdAbonne())->filterByDateFin(null)->findOne();
    if(count($utilisation)<1)
        atomik::flash('utilisation null');
    $byciclette=  TabBycicletteQuery::create()->filterByIdByciclette($utilisation->getFkByciclette())->findOne();
    if($infoStation->getAvailableBikeStands()>0){
        $utilisation->setDateFin(new DateTime());
        $utilisation->setFkStationArrivee($station->getIdStation());
        $utilisation->save();
        $byciclette->setStatusByciclette(0);
        $byciclette->save();
        echo "Vous venez de rendre votre vélo.";
    }else{
        echo "Désolé, plus aucun stand de disponible";
    }
    
?>
